package com.base.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author innocent
 * @date 2019/1/17 18:39
 */
public class MyFixedThreadPool {
    public static void main(String[] args) {
//        创建一个可重用固定线程数的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 9; i++) {
            executorService.execute(new MyThread(i));
        }
        executorService.shutdown();
    }


}

/* 创建线程类 */

/**
 *
 */
class MyThread extends Thread{

    private int num;

    public MyThread(int num) {
        this.num = num;
    }

    public MyThread() {

    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "正在执行" + num);
    }
}
